/***********************************************************************
    filename:   CEGUIDirect3D9RenderTarget.h
    created:    Tue Feb 10 2009
    author:     Paul D Turner
*************************************************************************/

#ifndef _HgeRenderTarget_h_
#define _HgeRenderTarget_h_

#include "hgeRenderer.h"
#include "hgeRenderTarget.h"
#include "hgeRect.h"
#include <d3dx9.h>

#if defined(_MSC_VER)
#   pragma warning(push)
#   pragma warning(disable : 4251)
#endif

/*!
\brief
    Intermediate Direct3D9 implementation of a RenderTarget.
*/
class RenderTarget
{
public:
    //! Constructor
    RenderTarget(Renderer& owner);

    // implement parts of RenderTarget interface
    void draw(const GeometryBuffer& buffer);
    void draw(const RenderQueue& queue);
    void setArea(const hgeRect& area);
    const hgeRect& getArea() const;
    void activate();
    void deactivate();
    void unprojectPoint(const GeometryBuffer& buff, const Vector2& p_in, Vector2& p_out) const;

	virtual bool isImageryCache() const = 0;

protected:
    //! helper that initialises the cached matrix
    void updateMatrix() const;
    //! helper to initialise the D3DVIEWPORT9 \a vp for this target.
    void setupViewport(D3DVIEWPORT9& vp) const;

    //! Direct3D9Renderer that created this object
	Renderer& d_owner;
    //! Direct3DDevice9 interface obtained from our owner.
    LPDIRECT3DDEVICE9 d_device;
    //! holds defined area for the RenderTarget
    hgeRect d_area;
    //! projection / view matrix cache
    mutable D3DXMATRIX d_matrix;
    //! true when d_matrix is valid and up to date
    mutable bool d_matrixValid;
    //! tracks viewing distance (this is set up at the same time as d_matrix)
    mutable float d_viewDistance;
};

#if defined(_MSC_VER)
#   pragma warning(pop)
#endif

#endif  // end of guard _HgeRenderTarget_h_
